﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "ApplicationImpl.h"
#include "IApplication.h"
#include "IApplicationConfig.h"
#include "IApplicationEvent.h"
#include "ISplashScreen.h"
#include "EventHandler\DocumentEventHandler.h"
#include "EventHandler\ApplicationEventHandler.h"
#include "EventHandler\MainWindowEventHandler.h"
#include "IApplicationWindowEvent.h"
#include "IMainWindow.h"
#include "UiBuilder.h"
#include "IDocumentManager.h"
#include "IDocumentEvent.h"
#include "IHotKeyConfig.h"
// gdmp
#ifdef UiAdapter_IMPL
#include "GDFoundation/UiService.h"
#pragma endregion
#endif // UiAdapter_IMPL
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 

using namespace Sample;
using namespace gcmp;

ApplicationObserver::ApplicationObserver(gcmp::IApplication* app)
{
}

ApplicationObserver::~ApplicationObserver()
{
}

void ApplicationObserver::Init(gcmp::IApplication* app)
{
    //1.1、设置启动画面，可选
    gcmp::ISplashScreen* pSplashScreen = app->GetSplashScreen();
    pSplashScreen->SetImagePath(L":/images/SplashScreen/600x600.png");
    pSplashScreen->Show();

    //1.2、配置应用程序图标(任务栏)
    IApplicationConfig *pAppConfig = app->GetConfig();
    pAppConfig->SetApplicationIconPath(L":/images/Application/64x64.png");

    //1.3、增加主程序消息捕获处理
    //注册监听应用程序事件处理器
    IApplicationEvent* pApplicationEvent = app->GetApplicationEvent();
    if (pApplicationEvent)
    {
        m_opApplicationEventHandler = NEW_AS_OWNER_PTR(ApplicationEventHandler);
        pApplicationEvent->Add(m_opApplicationEventHandler.get());
    }

    //设置快捷键配置文件的路径
    if (IHotKeyConfig* pConfig = IHotKeyConfig::Get())
    {
        pConfig->SetHotKeyConfigFilePath(L"HotKeyConfig.xml");
        pConfig->LoadHotKeyConfig();
    }
}

void ApplicationObserver::BindWindowEvent(gcmp::IApplicationWindow* appView)
{
    //2.1、注册监听主窗口事件处理器
    IApplicationWindowEvent* pMainWindowEvent = IMainWindow::GetMainWindow()->GetMainWindowEvent();
    if (pMainWindowEvent)
    {
        m_opMainWindowEventHandler = NEW_AS_OWNER_PTR(MainWindowEventHandler);
        pMainWindowEvent->Add(m_opMainWindowEventHandler.get());
    }
}

void Sample::InitUiSkin(const gcmp::IApplicationWindow* pApplicationWindow)
{
#ifdef UiAdapter_IMPL
    gdmp::UiService::InitUiSkin(pApplicationWindow);
#endif

}